import { GameSprite } from "../../../../../com/gengine/game/core/GameSprite";
import { SEntityId } from "../../../../../Message/Public/SEntityId";
import { SDropItem } from "../../../../../Message/Public/SDropItem";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { ItemData } from "../../../resource/info/ItemData";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { BaseItem } from "../../common/BaseItem";
import { ObjCreate } from "../../common/ObjCreate";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { Global } from "../../../../../com/gengine/global/Global";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
//class DefendCopyDropItem
    
    export  class DefendCopyDropItem extends GameSprite
    {
        constructor()
        {
            super();
            this.createChildren();
            return;
        }

        public get entityId(): SEntityId
        {
            if (this._dropItem) 
            {
                return this._dropItem.entityId;
            }
            return null;
        }

        public updateInfo(arg1: SDropItem): void
        {
            var loc1=null;
            this._dropItem = arg1;
            if (arg1) 
            {
                loc1 = GameMapUtil.getPixelPoint(arg1.point.x, arg1.point.y);
                this.x = loc1.x;
                this.y = loc1.y;
                this._baseItem.itemData = new ItemData(arg1.playerItem.itemCode);
                this._baseItem.amount = 0;
                this._nameLabel.htmlText = this._baseItem.itemData.itemInfo.item.name;
            }
            else 
            {
                this._baseItem.itemData = null;
                this._nameLabel.htmlText = "";
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            this._dropItem = null;
            this._nameLabel = null;
            this._baseItem = null;
            this._bg = null;
            while (this.numChildren > 0) 
            {
                this.removeChildAt(0);
            }
            return;
        }

        protected createChildren(): void
        {
            var loc1=null;
            this._bg = new GImageBitmap("DefendPropCardBg");
            this.addChild(this._bg);
            loc1 = ResouceConst.getScaleBitmap("PackItemBg");
            loc1.x = 8;
            loc1.y = 8;
            loc1.width = 66;
            loc1.height = 66;
            this.addChild(loc1);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(60, 60);
            this._baseItem.x = loc1.x + 3;
            this._baseItem.y = loc1.y + 3;
            this.addChild(this._baseItem);
            this._nameLabel = ObjCreate.createLabel("", 0, 90, 83, 20, flash.text.TextFormatAlign.CENTER, this, false, 16776960);
            return;
        }

        public /* override */ hoverTest(): Boolean
        {
            var loc1=0;
            if (!(this._bg == null) && DisplayUtil.isBitmapDataUsable(this._bg.bitmapData)) 
            {
                loc1 = this._bg.bitmapData.getPixel32(this._bg.mouseX, this._bg.mouseY);
                return loc1 > 0;
            }
            return this._bg.hitTestPoint(Global.stage.mouseX, Global.stage.mouseY);
        }

        /* internal */ /* var */_dropItem: SDropItem;

        /* internal */ /* var */_bg: GImageBitmap;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_nameLabel: GLabel;
    }
